<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>运行时配置</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="apcu.installation.html">« 安装</a></li>
      <li style="float: right;"><a href="apcu.resources.html">资源类型 »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="apcu.setup.html">安装/配置</a></li>
    <li>运行时配置</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="apcu.configuration" class="section">
 <h2 class="title">运行时配置</h2>
 <p class="simpara">
这些函数的行为受 <var class="filename">php.ini</var> 中的设置影响。
</p>
 <p class="para">
  Although the default APCu settings are fine for many installations, serious
  users should consider tuning the following parameters.
 </p>
 <p class="para">
  There is one decision to be made configuring APCu.  
  How much memory is going to be allocated to APCu.
  The ini directive that controls this is <code class="literal">apc.shm_size</code>
  Read the sections on this carefully below.
 </p>
 <p class="para">
  Once the server is running, the <code class="literal">apc.php</code> script that
  is bundled with the extension should be copied somewhere into the docroot and
  viewed with a browser as it provides a detailed analysis of the internal 
  workings of APCu. If GD is enabled in PHP, it will even display some
  interesting graphs.</p>
  <p class="para">
  If APCu is working, the <code class="literal">Cache full count
  </code> number (on the left) will display the number of times the cache
  has reached maximum capacity and has had to evict entries to free up memory.
  During eviction, if <code class="literal">apc.ttl</code> was specified, APCu will first
  attempt to remove expired entries, i.e. entries whose TTL has either expired,
  or entries that have no TTL set and haven&#039;t been accessed in the last
  <code class="literal">apc.ttl</code> seconds. If <code class="literal">apc.ttl</code> was not set,
  or removing expired entries did not free up enough space, APCu will clear the
  entire cache.
  </p>
  <p class="para">
  The number of evictions should be minimal in a well-configured cache. If the
  cache is constantly being filled, and thusly forcefully freed, the resulting
  churning will have disparaging effects on script performance. The easiest way
  to minimize this number is to allocate more memory for APCu.
 </p>
 <p class="para">
  When APCu is compiled with mmap support (Memory Mapping), it will use only one 
  memory segment, unlike when APCu is built with SHM (SysV Shared Memory) support 
  that uses multiple memory segments. MMAP does not have a maximum limit like SHM 
  does in <code class="literal">/proc/sys/kernel/shmmax</code>. In general MMAP support is 
  recommended because it will reclaim the memory faster when the webserver is 
  restarted and all in all reduces memory allocation impact at startup.
 </p>
 <p class="para">
  <table class="doctable table">
   <caption><strong>APCu configuration options</strong></caption>
   
    <thead>
     <tr>
      <th>名字</th>
      <th>默认</th>
      <th>可修改范围</th>
      <th>更新日志</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td><a href="apcu.configuration.html#ini.apcu.enabled" class="link">apc.enabled</a></td>
      <td>&quot;1&quot;</td>
      <td>PHP_INI_SYSTEM</td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td><a href="apcu.configuration.html#ini.apcu.shm-segments" class="link">apc.shm_segments</a></td>
      <td>&quot;1&quot;</td>
      <td>PHP_INI_SYSTEM</td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td><a href="apcu.configuration.html#ini.apcu.shm-size" class="link">apc.shm_size</a></td>
      <td>&quot;32M&quot;</td>
      <td>PHP_INI_SYSTEM</td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td><a href="apcu.configuration.html#ini.apcu.entries-hint" class="link">apc.entries_hint</a></td>
      <td>&quot;4096&quot;</td>
      <td>PHP_INI_SYSTEM</td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td><a href="apcu.configuration.html#ini.apcu.ttl" class="link">apc.ttl</a></td>
      <td>&quot;0&quot;</td>
      <td>PHP_INI_SYSTEM</td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td><a href="apcu.configuration.html#ini.apcu.gc-ttl" class="link">apc.gc_ttl</a></td>
      <td>&quot;3600&quot;</td>
      <td>PHP_INI_SYSTEM</td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td><a href="apcu.configuration.html#ini.apcu.mmap-file-mask" class="link">apc.mmap_file_mask</a></td>
      <td>NULL</td>
      <td>PHP_INI_SYSTEM</td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td><a href="apcu.configuration.html#ini.apcu.slam-defense" class="link">apc.slam_defense</a></td>
      <td>&quot;1&quot;</td>
      <td>PHP_INI_SYSTEM</td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td><a href="apcu.configuration.html#ini.apcu.enable-cli" class="link">apc.enable_cli</a></td>
      <td>&quot;0&quot;</td>
      <td>PHP_INI_SYSTEM</td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td><a href="apcu.configuration.html#ini.apcu.use-request-time" class="link">apc.use_request_time</a></td>
      <td>&quot;0&quot;</td>
      <td>PHP_INI_ALL</td>
      <td>Prior to APCu 5.1.19, the default was &quot;1&quot;.</td>
     </tr>

     <tr>
      <td><a href="apcu.configuration.html#ini.apcu.serializer" class="link">apc.serializer</a></td>
      <td>&quot;php&quot;</td>
      <td>PHP_INI_SYSTEM</td>
      <td>Prior to APCu 5.1.15, the default was &quot;default&quot;.</td>
     </tr>

     <tr>
      <td><a href="apcu.configuration.html#ini.apcu.coredump-unmap" class="link">apc.coredump_unmap</a></td>
      <td>&quot;0&quot;</td>
      <td>PHP_INI_SYSTEM</td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td><a href="apcu.configuration.html#ini.apcu.preload-path" class="link">apc.preload_path</a></td>
      <td>NULL</td>
      <td>PHP_INI_SYSTEM</td>
      <td class="empty">&nbsp;</td>
     </tr>

    </tbody>
   
  </table>

  有关 PHP_INI_* 样式的更多详情与定义，见 <a href="configuration.changes.modes.html" class="xref">配置可被设定范围</a>。
 </p>
 
 <p class="para">这是配置指令的简短说明。</p>
 
 <p class="para">
  <dl>
   
    <dt id="ini.apcu.enabled">
     <code class="parameter">apc.enabled</code>
     <span class="type">bool</span>
    </dt>

    <dd>

     <p class="para">
      <code class="literal">apc.enabled</code> can be set to 0 to disable APC. This is
      primarily useful when APC is statically compiled
      into PHP, since there is no other way to disable
      it (when compiled as a DSO, the <code class="literal">extension</code>
      line in <code class="literal">php.ini</code> can just be commented-out).
     </p>
    </dd>

   
   
    <dt id="ini.apcu.shm-segments">
     <code class="parameter">apc.shm_segments</code>
     <span class="type">int</span>
    </dt>

    <dd>

     <p class="para">
      The number of shared memory segments to allocate
      for the compiler cache. If APC is running out of
      shared memory but <code class="literal">apc.shm_size</code> 
      is set as high as the system allows, raising
      this value might prevent APC from exhausting its memory.
     </p>
    </dd>

   
   
    <dt id="ini.apcu.shm-size">
     <code class="parameter">apc.shm_size</code>
     <span class="type">string</span>
    </dt>

    <dd>

     <p class="para">
      The size of each shared memory segment given by a shorthand notation as
      described in <a href="faq.using.html#faq.using.shorthandbytes" class="link">this FAQ</a>.
      By default, some systems (including most BSD
      variants) have very low limits on the size of a
      shared memory segment.
     </p>
    </dd>

   
   
    <dt id="ini.apcu.entries-hint">
     <code class="parameter">apc.entries_hint</code>
     <span class="type">int</span>
    </dt>

    <dd>

     <p class="para">
      A &quot;hint&quot; about the number of distinct variables that might be stored.
      Set to zero or omit if not sure.
     </p>
    </dd>

   
   
    <dt id="ini.apcu.ttl">
     <code class="parameter">apc.ttl</code>
     <span class="type">int</span>
    </dt>

    <dd>

     <p class="para">
      Consider cache entries without an explicit TTL to be
      expired if they have not been accessed in this many
      seconds. Effectively, this allows such entries to be
      removed opportunistically during a cache insert, or
      prior to a full expunge. Note that because removal is
      opportunistic, entries can still be readable even if
      they are older than <code class="literal">apc.ttl</code> seconds.
      This setting has no effect on cache entries that have
      an explicit TTL specified.
     </p>
    </dd>

   
   
    <dt id="ini.apcu.gc-ttl">
     <code class="parameter">apc.gc_ttl</code>
     <span class="type">int</span>
    </dt>

    <dd>

     <p class="para">
      The number of seconds that a cache entry may
      remain on the garbage-collection list. This value
      provides a fail-safe in the event that a server
      process dies while executing a cached source file;
      if that source file is modified, the memory
      allocated for the old version will not be
      reclaimed until this TTL reached. Set to zero to
      disable this feature.
     </p>
    </dd>

   
   
    <dt id="ini.apcu.mmap-file-mask">
     <code class="parameter">apc.mmap_file_mask</code>
     <span class="type">string</span>
    </dt>

    <dd>

     <p class="para">
      If compiled with MMAP support by using <code class="literal">--enable-mmap</code>
      this is the mktemp-style file_mask to pass to the
      mmap module for determining whether your mmap&#039;ed memory
      region is going to be file-backed or shared memory
      backed.  For straight file-backed mmap, set it to
      something like <code class="literal">/tmp/apc.XXXXXX</code>
      (exactly 6 <code class="literal">X</code>s).
      To use POSIX-style shm_open/mmap put a <code class="literal">.shm</code>
      somewhere in your mask.  e.g. <code class="literal">/apc.shm.XXXXXX</code>
      You can also set it to <code class="literal">/dev/zero</code> to use your
      kernel&#039;s <code class="literal">/dev/zero</code> interface to anonymous mmap&#039;ed
      memory. Leaving it undefined will force an anonymous mmap.
     </p>
    </dd>

   
   
    <dt id="ini.apcu.slam-defense">
     <code class="parameter">apc.slam_defense</code>
     <span class="type">int</span>
    </dt>

    <dd>

     <p class="para">
      On very busy servers whenever you start the server or
      modify files you can create a race of many processes
      all trying to cache the same file at the same time.
      This option sets the percentage of processes that will
      skip trying to cache an uncached file.  Or think of it
      as the probability of a single process to skip caching.
      For example, setting <code class="literal">apc.slam_defense</code>
      to <code class="literal">75</code> would mean that there is
      a 75% chance that the process will not cache an uncached
      file. So, the higher the setting the greater the defense
      against cache slams.  Setting this to <code class="literal">0</code>
      disables this feature.
     </p>
    </dd>

   
   
    <dt id="ini.apcu.enable-cli">
     <code class="parameter">apc.enable_cli</code>
     <span class="type">int</span>
    </dt>

    <dd>

     <p class="para">
      Mostly for testing and debugging.  Setting this enables APC
      for the CLI version of PHP.  Under normal circumstances, it is
      not ideal to create, populate and destroy the APC cache on every
      CLI request, but for various test scenarios it is useful to be
      able to enable APC for the CLI version of PHP easily.
     </p>
    </dd>

    
   
    <dt id="ini.apcu.serializer">
     <code class="parameter">apc.serializer</code>
     <span class="type">string</span>
    </dt>

    <dd>

     <p class="para">
      Used to configure APC to use a third party serializer.
     </p>
    </dd>

   
   
    <dt id="ini.apcu.coredump-unmap">
     <code class="parameter">apc.coredump_unmap</code>
     <span class="type">bool</span>
    </dt>

    <dd>

     <p class="para">
      Enables APC handling of signals, such as SIGSEGV, that write
      core files when signaled. When these signals are received,
      APC will attempt to unmap the shared memory segment in order
      to exclude it from the core file. This setting may improve
      system stability when fatal signals are received and a large 
      APC shared memory segment is configured.
     </p>
     <div class="warning"><strong class="warning">警告</strong>
      <p class="para">
       This feature is potentially dangerous. Unmapping the shared
       memory segment in a fatal signal handler may cause undefined
       behaviour if a fatal error occurs.
      </p>
     </div>
     <blockquote class="note"><p><strong class="note">注意</strong>: 
      <p class="para">
       Although some kernels may provide a facility to ignore various
       types of shared memory when generating a core dump file, these 
       implementations may also ignore important shared memory segments
       such as the Apache scoreboard.
      </p>
     </p></blockquote>
    </dd>

   
   
    <dt id="ini.apcu.preload-path">
     <code class="parameter">apc.preload_path</code>
     <span class="type">string</span>
    </dt>

    <dd>

     <p class="para">
      Optionally, set a path to the directory that APC will load 
      cache data at startup.
     </p>
    </dd>

   

   
    <dt id="ini.apcu.use-request-time">
     <code class="parameter">apc.use_request_time</code>
     <span class="type">bool</span>
    </dt>

    <dd>

     <p class="para">
      Use the <abbr title="Server Application Programming Interface">SAPI</abbr> request start time for
      <abbr>TTL</abbr>.
     </p>
    </dd>

   
  </dl>

 </p>
</div></div></div></body></html>